<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>阈值编辑</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<link href="css/mui.picker.css" rel="stylesheet" />
		<link href="css/mui.poppicker.css" rel="stylesheet" />
		<!--<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />-->
		<style>
			.mui-btn {
				font-size: 16px;	
				padding: 8px;
				margin: 3px;
			}
			h5.mui-content-padded {
				margin-left: 3px;
				margin-top: 20px !important;
			}
			h5.mui-content-padded:first-child {
				margin-top: 12px !important;
			}
			.ui-alert {
				text-align: center;
				padding: 20px 10px;
				font-size: 16px;
			}
		</style>
		
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">阈值编辑</h1>
		</header>
		<div class="mui-content">
			<div class="mui-card">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<div class="mui-collapse-content">
							<form class="mui-input-group">
								<div class="mui-input-row">
									<label>阈值名：</label>
									<input type="text" id="Name" placeholder="请输入阈值名称" maxlength="30">
								</div>
								<div class="mui-input-row">
									<label>范围：</label>							
									<div class='mui-table-view-cell' style="padding: 0;margin: 0;">
										 <div class='mui-table-cell mui-col-sm-5'>
											 <input type="text" id="StartValue" placeholder="开始值" maxlength="30">
										 </div>
										 <div class='mui-table-cell mui-col-sm-1'>-</div>
										 <div class='mui-table-cell mui-col-sm-5'>
											 <input type="text" id="EndValue" placeholder="结束值" maxlength="30">
										 </div>
									 </div>
								</div>	
								<div class="mui-button-row">
									<button class="mui-btn mui-btn-primary" type="button" onclick="Threshold_Save();">保存</button>&nbsp;&nbsp;
									<button class="mui-btn mui-btn-danger" style="display: none;" id="btnDel" type="button" onclick="Threshold_Del();">删除</button>&nbsp;&nbsp;
									<button class="mui-btn" type="button" onclick="Core.Tool.Back()">取消</button>
								</div>
							</form>
						</div>
					</li>					
				</ul>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/mui.picker.js"></script>
		<script src="js/mui.poppicker.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="libs/lib.js"></script>
		<script>
			var Model = {};
			var isAdd = true;
			
			(function($, doc) {
				mui.init({
					swipeBack:true //启用右滑关闭功能
				});
				
				var userPicker = new $.PopPicker();
				Page_Init();			
				
				function Page_Init(){	
					Threshold_Get_Info();
					if(isAdd == false)
						document.getElementById("btnDel").style.display = "";
				}
				
			})(mui, document);
			

			function Threshold_Get_Info(){						
				var param = Core.Tool.QueryUrlString("id");
				if(param && param.id){
					isAdd = false;
					Core.Post("Threshold/GetModel", param, function(result, status){
						if(result.errorMsg){
							Core.Msg.Alert(result.errorMsg);
							return;
						}
						
						Model = result.data;
						document.getElementById("Name").value = Model.name;
						document.getElementById("StartValue").value = Model.startValue;
						document.getElementById("EndValue").value = Model.endValue;
					});
				}				
			}
			
			function Threshold_Save(){
				var url = Model && Model.id ? "Threshold/Edit" : "Threshold/Add";
				Model.name = document.getElementById("Name").value;
				Model.startValue = document.getElementById("StartValue").value;
				Model.endValue = document.getElementById("EndValue").value;
				Core.Post(url, { Param: Model }, function(result, status){
					if(result.errorMsg){
						Core.Msg.Alert(result.errorMsg);
						return;
					}
					Core.Tool.Back();
				});
			}
			
			function Threshold_Del(){
				Core.Msg.Confirm("您确定要删除该数组吗？",null , null, function(){
					if(!Model)
						return;
				Core.Post("Threshold/Del", { id: Model.id }, function(result, status){
					if(result.errorMsg){
						Core.Msg.Alert(result.errorMsg);
						return;
					}
					Core.Tool.Back();
				});
				})
			}
		</script>
	</body>

</html>